package pl.dsp.dsp1.processing;

import java.util.ArrayList;
import java.util.List;

public class SimpleValue implements SignalValue {

	public SimpleValue(double value)
	{
		this.value = value;
	}
	
	public SimpleValue(SignalValue value) {
		this.value = value.getValues().get(0);
	}

	public double getValue()
	{
		return value;
	}
	
	@Override
	public List<Double> getValues() {
		ArrayList<Double> result = new ArrayList<Double>(1);
		result.add(value);
		return result;
	}

	@Override
	public SignalValue add(SignalValue another) {
		return new SimpleValue(value + new SimpleValue(another).value);
	}

	@Override
	public SignalValue substract(SignalValue another) {
		return new SimpleValue(value - new SimpleValue(another).value);
	}

	@Override
	public SignalValue multiply(SignalValue another) {
		return new SimpleValue(value * new SimpleValue(another).value);
	}

	@Override
	public SignalValue divide(SignalValue another) {
		double anotherValue = new SimpleValue(another).value;
		anotherValue = anotherValue == 0 ? 0.0000001 : anotherValue;
		return new SimpleValue(value / anotherValue);
	}

	private double value;

	@Override
	public SignalValue abs() {
		return new SimpleValue(Math.abs(value));
	}

	@Override
	public Object clone() {
		return new SimpleValue(this);
	}

	@Override
	public SignalValue conjugate() {
		return (SignalValue) this.clone();
	}
}
